﻿@{
    ViewBag.Title = "查询添加数据库";
    Layout = "~/Views/Shared/PlanPartial/_LayoutSearch.cshtml";
}
@{
    var Key = ViewData["Key"] as string;
    var Version = ViewData["Version"] as List<string>;
}
<div>
    <input type="hidden" value="@(Key)" id="searchKey" />
    <input type="text" style="width: 300px;" value="@(Key)" class="easyui-searchbox" data-options="prompt:'输入数据库名或者IP地址或者用途进行搜索',searcher:doSearch" />
</div>
<div class="parameter">
    <div class="parameter_name" style="width: 90px;">数据库版本：</div>
    <div class="parameter_input" style="width: 150px;">
        <select style="width: 120px;" id="serverType">
            <option value="">全部</option>
            @foreach (var item in Version)
            { 
                <option value="@item">@item</option>
            }
        </select>
    </div>
</div>
<div style="padding: 10px 0;">
    <table id="DatabaseSys" class="" title="数据库"
        fitcolumns="true" pagination="true">
        <thead>
            <tr>
                <th data-options="field:'ck',checkbox:true">全选</th>
                <th field="DbAndVersion" width="120" sortable="true">数据库版本</th>
                <th field="IPAddress" width="120" sortable="true">IP地址</th>
                <th field="Usaged" width="120" sortable="true">用途</th>
            </tr>
        </thead>
    </table>
</div>

<script type="text/javascript">
    var doSearch = function (value) {
        var parenter = GetParentWindow(),
            list = [];
        if (parenter) {
            list = parenter.InspObj.GetRequestIDList('DatabaseSys');
        }

        var query = { Key: value, ServerType: $('#serverType').val(), ExcludeIDList: JSON.stringify(list) };
        $('#DatabaseSys').datagrid('load', query);
    };

    var AddRow = function () {
        var parenter = GetParentWindow();

        if (parenter) {

            var selects = parenter.InspObj.SelectArray["DatabaseSys"] || [];

            if (selects.length) {
                parenter.InspObj.AddDBSystem(selects);
                parenter.InspObj.SelectArray["DatabaseSys"] = [];
                closeWindow();
            }
        }
    };

    $(function () {
        var parenter = GetParentWindow(),
            list = [];
        if (parenter) {
            list = parenter.InspObj.GetRequestIDList('DatabaseSys');
        }

        var query = { Key: $('#searchKey').val(), ServerType: $('#serverType').val(), ExcludeIDList: JSON.stringify(list) };

        $('#DatabaseSys').datagrid({
            url: '/PlanManagement/SearchDBResult',
            pageList: [10],
            pageSize: 10,
            pageNumber: 1,
            queryParams: query,
            onLoadSuccess: function (data) {
                parenter.InspObj.onLoadSuccess(data.rows, "DatabaseSys", $('#DatabaseSys'));
            },
            onCheck: function (index, row) {
                parenter.InspObj.OnSelect(index, row, "DatabaseSys");
            },
            onUncheck: function (index, row) {
                parenter.InspObj.OnUnSelect(index, row, "DatabaseSys");
            },
            onCheckAll: function (rows) {
                parenter.InspObj.OnSelectAll(rows, "DatabaseSys");
            },
            onUncheckAll: function (rows) {
                parenter.InspObj.OnUnSelectAll(rows, "DatabaseSys");
            }
        });

        var p2 = $('#DatabaseSys').datagrid('getPager');
        $(p2).pagination({
            beforePageText: '第',
            afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
            displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

        });
    });
</script>
